package net.zdreamer.geracomium.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.geracomium.R;

import net.zdreamer.geracomium.entity.AssessInfos;
import net.zdreamer.geracomium.ui.home.DoAssessActivity;
import net.zdreamer.geracomium.utils.tools_utils.ViewHolder;

import java.util.List;

/**
 * Created by Administrator on 2015/1/21.
 */
public class AssessContenAdapter extends MyBaseAdapter<AssessInfos.Assessinfo> implements AdapterView.OnItemClickListener {
    private Context mContext;
    private ImageView ischoiced;
    private List<AssessInfos.Assessinfo> mList;

    public AssessContenAdapter(Context context, List<AssessInfos.Assessinfo> list, int res) {
        super(context, list, res);
        this.mContext = context;
        this.mList = list;
    }

    @Override
    protected View getView(int position, View convertView, ViewGroup parent, AssessInfos.Assessinfo value) {
        TextView answer = ViewHolder.get(convertView, R.id.choice);
        ischoiced = ViewHolder.get(convertView, R.id.selected);
        answer.setText(value.answer);
        if (!value.ischecked) {

            ischoiced.setImageResource(value.map.get("unchoice"));
        } else {
            ischoiced.setImageResource(R.drawable.selected);
        }
        // ischoiced.setImageResource(R.drawable.unselected);
        return convertView;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        for (int i = 0; i < mList.size(); i++) {
            if (i == position) {
                mList.get(i).ischecked = true;
                DoAssessActivity.selectedId = position;
                DoAssessActivity.choices.add(mList.get(i).score);
            } else {
                mList.get(i).ischecked = false;
            }

            this.notifyDataSetChanged();
        }
    }

//    void setSelected(int which) {
//        for (int i = 1; i <= mList.size(); i++) {
//            imageViews[i - 1].setImageResource(
//                    i == which ? R.drawable.selected : R.drawable.unselected);
//            DoAssessActivity.selectedId = which;
//        }
//    }
}
